package com.errol.batchprocessor.batchprocessor.bo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 批处理线程池运行状态
 *
 * @author zhang xiao bin
 * @version v1.0
 * @date 2021/03/10
 * @since v5.0.6
 **/
@Getter
@ApiModel
public class ThreadPoolStatusBO {

    @ApiModelProperty("线程池核心线程数")
    private final int corePoolSize;
    @ApiModelProperty("线程池最大线程数")
    private final int maximumPoolSize;
    @ApiModelProperty("当前线程池中线程数")
    private final int poolSize;
    @ApiModelProperty("线程池线程数峰值")
    private final int largestPoolSize;
    @ApiModelProperty("等待中的分片数量")
    private final int queueSize;
    @ApiModelProperty("等待队列剩余容量")
    private final int queueRemainSize;

    public ThreadPoolStatusBO(ThreadPoolExecutor executor) {
        corePoolSize = executor.getCorePoolSize();
        maximumPoolSize = executor.getMaximumPoolSize();
        poolSize = executor.getPoolSize();
        largestPoolSize = executor.getLargestPoolSize();
        queueSize = executor.getQueue().size();
        queueRemainSize = executor.getQueue().remainingCapacity();
    }
}
